'''
Created on May 31, 2012

@author: mupet
'''

import wx
from syslogd.enums import Function, Priority, Selector, Specifier
from syslogd.configuration.Rule import Rule
from syslogd.configuration.ConfObject import ConfObject

class RuleAddWindow(wx.Frame):
    '''
    classdocs
    '''


    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.SetMinSize(wx.Size(700, 300))
        self.create_controls()
        
    def create_controls(self):
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizer)
        
        self.functionBox = wx.ComboBox(self, size=(120,30), style=wx.CB_READONLY, choices=Function.FunctionDict.keys())
        self.functionBox.Select(0)
        sizer.Add(self.functionBox)
        self.functionBox.Bind(wx.EVT_COMBOBOX, self.functionSelect)
        
        self.prioritySelectorBox = wx.ComboBox(self, size=(70,30), style=wx.CB_READONLY, choices=Selector.PrioritySelectorDict.keys())
        self.prioritySelectorBox.Select(0)
        sizer.Add(self.prioritySelectorBox)
        self.prioritySelectorBox.Bind(wx.EVT_COMBOBOX, self.prioritySelectorSelect)
        
        self.priorityBox = wx.ComboBox(self, size=(120,30), style=wx.CB_READONLY, choices=Priority.PriorityDict.keys())
        self.priorityBox.Select(0)
        sizer.Add(self.priorityBox)
        self.priorityBox.Bind(wx.EVT_COMBOBOX, self.prioritySelect)
        
        self.specifierBox = wx.ComboBox(self, size=(70,30), style=wx.CB_READONLY, choices=Specifier.SpecifierDict.keys())
        self.specifierBox.Select(0)
        sizer.Add(self.specifierBox)
        self.specifierBox.Bind(wx.EVT_COMBOBOX, self.specifierSelect)
        
        self.pathText = wx.TextCtrl(self, size=(120,30))
        sizer.Add(self.pathText)

        self.applyButton = wx.Button(self, size=(70,30), label='Add')
        sizer.Add(self.applyButton)
        self.applyButton.Bind(wx.EVT_BUTTON, self.addRule)
        
    def functionSelect(self, event):
        self.functionString = event.GetString()
        
    def prioritySelectorSelect(self, event):
        self.prioritySelectorString = event.GetString()
        
    def prioritySelect(self, event):
        self.priorityString = event.GetString()
        
    def specifierSelect(self, event):
        self.specifierString = event.GetString()
        
    def addRule(self, event):
        rule = Rule(self.functionBox.GetValue(), self.prioritySelectorBox.GetValue(), self.priorityBox.GetValue())
        confObject = ConfObject([rule],self.specifierBox.GetValue(),self.pathText.GetValue(), False)